// java.js
var api = require('../../../../service/api');
var app = getApp();
var apiUrl = app.apiUrl;
Page({
  /**
   * 页面的初始数据
   */
  data: {
    shown:"none",
    inputValue: '',
    face_array1: [],
    face_array2: [],
    face_array3: [],
    face_array4: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this;
    wx.showLoading({
      title: '加载中',
    })
    wx.request({
      url: 'https://www.wjp147.cn/e2face/strategy/apitoplist',
      data: { },
      method: "post",
      dataType: "json",
      header: {
        'Content-Type': 'application/json'
      },
      success: function (res) {
        wx.hideLoading();
        if(res.data.resultCode==111){
          var datas = res.data.resultDatas;
          var arry1 = [];  
          var arry2 = [];  
          var arry3 = [];  
          var arry4 = [];      
          for (var i = 0; i < datas.length;i++){
            if (datas[i].typeId ==1){
              if (arry1.length<5){
                arry1.push(datas[i]);
              }             
            } else if (datas[i].typeId == 2){
              if (arry2.length < 5) {
                arry2.push(datas[i]);
              }   
            } else if (datas[i].typeId == 3) {
              if (arry3.length < 5) {
                arry3.push(datas[i]);
              }   
            } else if (datas[i].typeId == 4) {
              if (arry4.length < 5) {
                arry4.push(datas[i]);
              }   
            }
          }
          that.setData({
            face_array1: arry1,
            face_array2: arry2,
            face_array3: arry3,
            face_array4: arry4
          });
        }
      }, error: function () {
        wx.navigateTo({ url: '../index/index' })
      }
    })
  },
  /**
   * 输入框值变化
   */
  bindKeyInput:function(e){
    var val = e.detail.value;
    if (val.length>0){
      this.setData({
        shown:"block",
        inputValue: val
      })
    }else{
      this.setData({
        shown: "none"
      })
    }
  },
  /**
   * 点击搜索
   */
  serachAction:function(e){
    var title = this.data.inputValue;
    console.log("---title:" + this.data.inputValue);
    wx.navigateTo({
      url: '../strategylist/strategylist?title=' + this.data.inputValue
    })
  },
  /**
   * 清空输入框
   */
  clearInput:function(){
    this.setData({
      shown: "none",
      inputValue: ''
    })
  },
  /**
   * 跳转到攻略信息
   */
  ToStrategy:function(e){
    var index = parseInt(e.currentTarget.dataset.index);
    console.log("--传递：" + index);
    wx.navigateTo({
      url: '../strategydetail/strategydatail?id='+ index
    })
  },
  /**
   * 跳转到攻略列表
   */
  ToStrategyDetail:function(e){
    var index = parseInt(e.currentTarget.dataset.index);
    wx.navigateTo({
      url: '../strategylist/strategylist?typeId=' + index
    })
  }
})